package com.hyz.service.impl;

import client.LogClient;
import com.hyz.pojo.ResponseResult;
import com.hyz.pojo.assetSecondment.AssetSecondmentRequest;
import com.hyz.pojo.assetSecondment.AssetSecondmentResponse;
import com.hyz.service.FinancialService;
import com.hyz.util.Conversion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.asset.Asset;
import pojo.log.IsComplete;
import pojo.log.assetSecondment.AssetSecondment;
import pojo.log.assetSecondment.AssetSecondmentResultEnum;
import pojo.log.assetSecondment.AssetSecondmentStatusEnum;

import java.util.List;

/**
 * @author HGD
 * @date 2022/10/6 21:24
 */
@Service
public class FinancialServiceImpl implements FinancialService {
    @Autowired
    private LogClient logClient;
    @Autowired
    private Conversion conversion;

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> fnlGetAssetSecondment() {
        AssetSecondment assetSecondment = AssetSecondment.builder()
                .isComplete(IsComplete.UNFINISHED)
                .result(AssetSecondmentResultEnum.CHARGE_LEADER_AGREE)
                .status(AssetSecondmentStatusEnum.TRANSFERS)
                .build();
        List<AssetSecondment> assetSecondments = logClient.getAssetSecondments(assetSecondment);
        List<AssetSecondmentResponse> responses = conversion.getAssetSecondmentResponse(assetSecondments);
        return new ResponseResult<>(200, "成功", responses);
    }

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> fnlUpdateAssetSecondment(AssetSecondmentRequest request) {
        AssetSecondment assetSecondment = AssetSecondment.builder()
                .id(request.getId())
                .result(request.getResult()
                        ? AssetSecondmentResultEnum.FINANCIAL_AGREE
                        : AssetSecondmentResultEnum.FAILED)
                .build();
        logClient.updateAssetSecondmentById(assetSecondment);
        return fnlGetAssetSecondment();
    }
}
